# -*- coding: utf-8 -*-
import numpy as np
import geatpy as ea
from Solution import Solution

class MyProblem(ea.Problem):
    def __init__(self): # 目标维数
        name = 'MyProblem'
        M = 1
        Dim = 6 # 决策变量维数
        maxormins = [-1] * M # 初始化最小化最大化标记
        varTypes = [1] * Dim # 初始化决策变量类型
        lb = [0] * Dim
        ub = [(72 - 8) * 60 * 60, (72 - 18) * 60 * 60, (72 - 18) * 60 * 60, 
            (72 - 8) * 60 * 60, (72 - 8) * 60 * 60, (72 - 10) * 60 * 60]
        lbin = [1] * Dim
        ubin = [1] * Dim

        ea.Problem.__init__(self, name, M, maxormins, Dim, varTypes, lb, ub, lbin, ubin)

    def aimFunc(self, pop):
        x = pop.Phen # 得到决策变量矩阵
        objV = []
        for i in range(x.shape[0]):
            s = Solution()
            s.init()
            ans = s.run2(x[i])
            objV.append(ans)
        pop.ObjV = np.array([objV]).T
